package com.tvserials.notification.services;

import com.tvserials.notification.dto.Episode;
import com.tvserials.notification.dto.Serial;
import com.tvserials.notification.exceptions.NetworkConnectionException;
import com.tvserials.notification.exceptions.PageParseException;
import com.tvserials.notification.parser.PageParser;
import com.tvserials.notification.parser.PageParserFactory;
import com.tvserials.notification.vo.SourceType;
import com.tvserials.notification.vo.TvEpisodeFilterVO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Alex on 01.05.2014.
 */
public class LocalNotificationService implements NotificationService {

    @Override
    public String userSignIn(String username, String password) {
        return "password";
    }

    @Override
    public List<Episode> getEpisodes(TvEpisodeFilterVO filterVO) throws NetworkConnectionException, PageParseException {
        List<Episode> episodes = new ArrayList<Episode>();
        for (SourceType sourceType : filterVO.getSourceTypes()) {
            PageParser pageParser = PageParserFactory.getPageParser(sourceType);
            try {
                episodes.addAll(pageParser.parsePage(filterVO));
            } catch (Exception e) {
                //continue loading
            }
        }
        return episodes;
    }

    @Override
    public List<Serial> getSerials(SourceType sourceType) throws NetworkConnectionException {
        PageParser pageParser = PageParserFactory.getPageParser(sourceType);
        List<Serial> serials = pageParser.parseSerialsList();
        return serials;
    }
}
